package com.jhgsys.internal.workflow.service.impl;

import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.workflow.entity.WorkflowApplyReviewLog;
import com.jhgsys.internal.workflow.mapper.WorkflowApplyReviewLogMapper;
import com.jhgsys.internal.workflow.service.IWorkflowApplyReviewLogService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 流程申请审核日志 Service实现
 *
 * @author fenghaijun
 * @date 2024-07-19 13:53:34
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class WorkflowApplyReviewLogServiceImpl extends ServiceImpl<WorkflowApplyReviewLogMapper, WorkflowApplyReviewLog> implements IWorkflowApplyReviewLogService {

    /**
     * 查询（分页）
     * @author fenghaijun
     * @date 2024-07-19 13:53:34
     * @param request QueryRequest
     * @param workflowApplyReviewLog workflowApplyReviewLog
     * @return IPage<WorkflowApplyReviewLog>
    */
    @Override
    public IPage<WorkflowApplyReviewLog> findWorkflowApplyReviewLogs(QueryRequest request, WorkflowApplyReviewLog workflowApplyReviewLog) {
        LambdaQueryWrapper<WorkflowApplyReviewLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WorkflowApplyReviewLog::getDeletedFlg, FebsConstant.VALID);
        // TODO 设置查询条件

        Page<WorkflowApplyReviewLog> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author fenghaijun
     * @date 2024-07-19 13:53:34
     * @param workflowApplyReviewLog workflowApplyReviewLog
     * @return List<WorkflowApplyReviewLog>
     */
    @Override
    public List<WorkflowApplyReviewLog> findWorkflowApplyReviewLogs(WorkflowApplyReviewLog workflowApplyReviewLog) {
	    LambdaQueryWrapper<WorkflowApplyReviewLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WorkflowApplyReviewLog::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author fenghaijun
    * @date 2024-07-19 13:53:34
    * @param id
    * @return WorkflowApplyReviewLog
    */
    @Override
    public WorkflowApplyReviewLog findWorkflowApplyReviewLogById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author fenghaijun
     * @date 2024-07-19 13:53:34
     * @param workflowApplyReviewLog workflowApplyReviewLog
     */
    @Override
    @Transactional
    public void createWorkflowApplyReviewLog(WorkflowApplyReviewLog workflowApplyReviewLog) {
        workflowApplyReviewLog.setCreatedTime(new Date());
        this.save(workflowApplyReviewLog);
    }

    /**
     * 修改
     * @author fenghaijun
     * @date 2024-07-19 13:53:34
     * @param workflowApplyReviewLog workflowApplyReviewLog
     */
    @Override
    @Transactional
    public void updateWorkflowApplyReviewLog(WorkflowApplyReviewLog workflowApplyReviewLog) {
        workflowApplyReviewLog.setUpdatedTime(new Date());
        this.saveOrUpdate(workflowApplyReviewLog);
    }

    /**
     * 逻辑删除
     * @author fenghaijun
     * @date 2024-07-19 13:53:34
     * @param workflowApplyReviewLog workflowApplyReviewLog
     * @param workflowApplyReviewLogIds workflowApplyReviewLogIds
     */
    @Override
    @Transactional
    public void deleteWorkflowApplyReviewLog(WorkflowApplyReviewLog workflowApplyReviewLog,String workflowApplyReviewLogIds) {
        List<String> list = Arrays.asList(workflowApplyReviewLogIds.split(StringPool.COMMA));
        this.baseMapper.update(workflowApplyReviewLog,new LambdaQueryWrapper<WorkflowApplyReviewLog>().in(WorkflowApplyReviewLog::getWorkflowApplyReviewLogId,list));
	}

    /**
    * 物理删除
    * @author fenghaijun
    * @date 2024-07-19 13:53:34
    * @param workflowApplyReviewLogIds workflowApplyReviewLogIds
    */
    @Override
    @Transactional
    public void physicallyDeleteWorkflowApplyReviewLog(String workflowApplyReviewLogIds) {
        List<String> list = Arrays.asList(workflowApplyReviewLogIds.split(StringPool.COMMA));
        LambdaQueryWrapper<WorkflowApplyReviewLog> wapper = new LambdaQueryWrapper<>();
        wapper.in(WorkflowApplyReviewLog::getWorkflowApplyReviewLogId,list);
        this.remove(wapper);
    }
}
